package system

// SetupKernelModulesOnAllNodes 配置所有节点的内核模块和系统参数
func (m *Manager) SetupKernelModulesOnAllNodes() error {
	// 准备内核模块配置命令
	commands := []string{
		"echo 'overlay\nbr_netfilter' | sudo tee /etc/modules-load.d/k8s.conf",
		"sudo modprobe overlay",
		"sudo modprobe br_netfilter",
		"echo 'net.bridge.bridge-nf-call-iptables  = 1\nnet.bridge.bridge-nf-call-ip6tables = 1\nnet.ipv4.ip_forward = 1' | sudo tee /etc/sysctl.d/k8s.conf",
		"sudo sysctl --system",
	}

	// 在所有节点上执行命令
	for _, cmd := range commands {
		if err := m.executeOnAllNodes(cmd); err != nil {
			return err
		}
	}
	return nil
}
